$(function(){
	$("#login").click(function(){
		var re = /^1(3|5|7|8)[0-9]{9}/
		var rx =/^[a-z0-9{6,16}]/
		console.log( $("#usen").val() == "")
		if( $("#pwd").val() == "" ){			
			$("#tishi").html("密码不能为空")
			//return
			
		}
		if( $("#usen").val() == "" ){			
			$("#tishi").html("账号不能为空")
			//return
		}
		if(re.test($("#usen").val()) == false){
			$("#tishi").html("请输入正确的手机号")
		}
		if(rx.test($("#pwd").val()) == false){
			$("#tishi").html("密码格式不正确")
		}else if(rx.test($("#pwd").val()) == true){
			$("#tishi").html("")
		
		}
		var use = $("#usen").val();
		var pwd = $("#pwd").val();
		var users = getCookie("register") ? getCookie("register") : "";
		users = convertStrToObj(users);
		console.log(users[use] )
		if(users[use] == pwd){
			
				setCookie("txt",use,7)
				alert("登录成功！")
				location.href = "../index.html";
			}else{
				alert("用户名和密码不匹配，请确认后重新输入")
			}
		
		
	})
	function convertStrToObj(str){
		if(!str){
			return {}
		}
		var users = str.split(":");
		var obj = {};
		for(var i = 0; i < users.length; i++){
			var userData = users[i].split(",");
			obj[userData[0]] = userData[1];
		}
		return obj;
	}
	function convertObjToStr(obj){
		var str = "";
		for(var usn in obj){
			var pwd = obj[usn];
			if(str){
				str += ":";
				
			}
			str += usn + "," +pwd;
		}
		return str;
	}
	
})
